package com.lipiao.smarthome.fragments;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lipiao.smarthome.RoomActivity.BathroomActivity;
import com.lipiao.smarthome.RoomActivity.BedroomActivity;
import com.lipiao.smarthome.RoomActivity.KitchenActivity;
import com.lipiao.smarthome.RoomActivity.LivingRoomActivity;
import com.lipiao.smarthome.R;
import com.lipiao.smarthome.RoomActivity.SecondBedroomActivity;

public class ControlFragment extends Fragment  {
    View rootView;
    CardView cvLivingRoom;
    CardView cvBedroom;
    CardView cvSecondBedroom;
    CardView cvKitchen;
    CardView cvBathroom;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_control, container, false);
        initView();
        initListener();
        return rootView;
    }

    private void initView() {
        cvLivingRoom = rootView.findViewById(R.id.card_living_room);
        cvBedroom = rootView.findViewById(R.id.card_main_bedroom);
        cvSecondBedroom = rootView.findViewById(R.id.card_second_bedroom);
        cvKitchen = rootView.findViewById(R.id.card_kitchen);
        cvBathroom = rootView.findViewById(R.id.card_bathroom);

    }

    private void initListener() {
        cvLivingRoom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity().getApplicationContext(), LivingRoomActivity.class);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity(), cvLivingRoom, "image").toBundle());
            }
        });
        cvBedroom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity().getApplicationContext(), BedroomActivity.class);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity(), cvBedroom, "image").toBundle());
            }
        });
        cvSecondBedroom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity().getApplicationContext(), SecondBedroomActivity.class);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity(), cvSecondBedroom, "image").toBundle());
            }
        });
        cvKitchen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity().getApplicationContext(), KitchenActivity.class);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity(), cvKitchen, "image").toBundle());
            }
        });
        cvBathroom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity().getApplicationContext(), BathroomActivity.class);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity(), cvBathroom, "image").toBundle());
            }
        });


    }

}
